home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / srgp_att.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  24.1 KB  |  886 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. #define __CURATT(xx)    srgp__curActiveCanvasSpec.attributes.xx
  5.  
  6.  
  7. #ifdef THINK_C
  8. #include "ChooseWhichQuickDraw.h"
  9. #endif
  10.  
  11. #ifdef X11
  12. static XGCValues gcvals;
  13.  
  14. static unsigned char writemode_table[4] = {
  15.    /*REPLACE*/  0x3, /* GXcopy from /usr/include/X11/X.h */
  16.    /*XOR*/      0x6, /* GXxor */
  17.    /*OR*/       0x7, /* GXor */
  18.    /*AND*/      0x1  /* GXand */
  19. };
  20.  
  21. static unsigned char inv_writemode_table[4] = {
  22.    /*REPLACE*/ 0x3, /* GXcopy */
  23.    /*XOR*/     0x9, /* GXequiv */
  24.    /*OR*/      0x1, /* GXand */
  25.    /*AND*/     0x7  /* GXor */
  26. };
  27.  
  28. #endif
  29.  
  30. #ifdef THINK_C
  31. #ifdef COLOR_QUICKDRAW
  32. static unsigned char transfermode_table[4][4] = {
  33.           /*REPLACE,SOLID*/ patCopy,
  34.           /* pixmap pattern entries in this table are unused */ 0,
  35.           /*REPLACE,BITMAP_PATTERN_TRANSPARENT*/ patOr,
  36.           /*REPLACE,BITMAP_PATTERN_OPAQUE*/ patCopy,
  37.           /*XOR,SOLID*/ patXor,
  38.           /* pixmap pattern entries in this table are unused */ 0,
  39.           /*XOR,BITMAP_PATTERN_TRANSPARENT*/ patXor,
  40.           /*XOR,BITMAP_PATTERN_OPAQUE*/ patXor,
  41.           /*OR,SOLID*/ patOr,
  42.           /* pixmap pattern entries in this table are unused */ 0,
  43.           /*OR,BITMAP_PATTERN_TRANSPARENT*/ patOr,
  44.           /*OR,BITMAP_PATTERN_OPAQUE*/ patOr,
  45.           /*AND,SOLID*/ notPatBic,
  46.           /* pixmap pattern entries in this table are unused */ 0,
  47.           /*AND,BITMAP_PATTERN_TRANSPARENT*/ notPatBic,
  48.           /*AND,BITMAP_PATTERN_OPAQUE*/ notPatBic
  49. };
  50.  
  51.  
  52. #define ComputeFrameTransfermode() \
  53.    srgp__curActiveCanvasSpec.transfermode_frame = \
  54.       transfermode_table \
  55.          [srgp__curActiveCanvasSpec.attributes.write_mode] \
  56.          [srgp__curActiveCanvasSpec.attributes.pen_style]
  57.  
  58. #define ComputeFillTransfermode() \
  59.    srgp__curActiveCanvasSpec.transfermode_fill = \
  60.       transfermode_table \
  61.          [srgp__curActiveCanvasSpec.attributes.write_mode] \
  62.          [srgp__curActiveCanvasSpec.attributes.fill_style]
  63.  
  64. #define SetTextTransfermode() \
  65.    TextMode (transfermode_table \
  66.                 [srgp__curActiveCanvasSpec.attributes.write_mode] \
  67.                 [BITMAP_PATTERN_TRANSPARENT] \
  68.              - 8)
  69.  
  70. #else
  71.  
  72. #define DONT_DRAW   -1
  73.  
  74. static unsigned char transfermode_table[4][2][4] = {
  75.   {
  76.         /*REPLACE,WHITE,...*/ {notPatCopy, 0, patBic, notPatCopy},
  77.         /*REPLACE,BLACK,...*/ {patCopy, 0, patOr, patCopy},
  78.   },
  79.   {
  80.         /*XOR,WHITE,...*/ {notPatXor, 0, DONT_DRAW, notPatXor},
  81.         /*XOR,BLACK,...*/ {patXor, 0, patXor, patXor}
  82.   },
  83.   {
  84.         /*OR,WHITE,...*/ {notPatOr, 0, DONT_DRAW, notPatOr},
  85.         /*OR,BLACK,...*/ {patOr, 0, patOr, patOr}
  86.   },
  87.   {
  88.         /*AND,WHITE,...*/ {patBic, 0, DONT_DRAW, patBic},
  89.         /*AND,BLACK,...*/ {notPatBic, 0, notPatBic, notPatBic}
  90.   }
  91. };
  92.  
  93.  
  94. static void ComputeFrameTransfermode (void)
  95. {
  96.    srgp__curActiveCanvasSpec.transfermode_frame =
  97.       transfermode_table[srgp__curActiveCanvasSpec.attributes.write_mode]
  98.                    [srgp__curActiveCanvasSpec.attributes.color]
  99.                    [srgp__curActiveCanvasSpec.attributes.pen_style];
  100. }
  101.  
  102. static void ComputeFillTransfermode (void)
  103. {
  104.    srgp__curActiveCanvasSpec.transfermode_fill =
  105.       transfermode_table[srgp__curActiveCanvasSpec.attributes.write_mode]
  106.                    [srgp__curActiveCanvasSpec.attributes.color]
  107.                    [srgp__curActiveCanvasSpec.attributes.pen_style];
  108. }
  109.  
  110. static void SetTextTransfermode (void) {
  111.    TextMode (transfermode_table
  112.                 [srgp__curActiveCanvasSpec.attributes.write_mode]
  113.                 [srgp__curActiveCanvasSpec.attributes.color]
  114.                 [BITMAP_PATTERN_TRANSPARENT]
  115.              - 8);
  116. }
  117.  
  118. #endif
  119.  
  120. #endif
  121.  
  122.  
  123. #ifdef GRX
  124.  
  125. #define C_CANVAS        (&srgp__curActiveCanvasSpec)
  126. #define C_ATTRIB        (&srgp__curActiveCanvasSpec.attributes)
  127.  
  128. static  int grx_mode_table[4] = { GrWRITE, GrXOR, GrOR, GrAND };
  129. static  unsigned char dash_patterns[4][5] = {
  130.     /*  length  pattern                               */
  131.     {   0                       },      /* CONTINUOUS */
  132.     {   4,      10, 5,  10, 5   },      /* DASHED     */
  133.     {   4,      4,  4,  4,  4   },      /* DOTTED     */
  134.     {   4,      12, 4,  4,  4   }       /* DOT_DASHED */
  135. };
  136.  
  137. void srgp__update_grx_penattributes(void)
  138. {
  139.         int wrtmode = grx_mode_table[C_ATTRIB->write_mode];
  140.         int fgcolor = COLORINDEX(C_ATTRIB->color) | wrtmode;
  141.         int realbgc = COLORINDEX(C_ATTRIB->background_color) | wrtmode;
  142.         int usedbgc = GrNOCOLOR;
  143.         int lnstyle = C_ATTRIB->line_style;
  144.  
  145.         C_CANVAS->grx_lineopt.lno_width   = C_ATTRIB->line_width;
  146.         C_CANVAS->grx_lineopt.lno_pattlen = dash_patterns[lnstyle][0];
  147.         C_CANVAS->grx_lineopt.lno_dashpat = &dash_patterns[lnstyle][1];
  148.         switch(C_ATTRIB->pen_style) {
  149.           case SOLID:
  150.             if((lnstyle != CONTINUOUS) || (C_ATTRIB->line_width > 1)) {
  151.                 C_CANVAS->grx_lineopt.lno_color = fgcolor;
  152.                 C_CANVAS->grx_pen_data.lo = &C_CANVAS->grx_lineopt;
  153.                 C_CANVAS->grx_pen_style = GRX_pen_dashed;
  154.                 return;
  155.             }
  156.             C_CANVAS->grx_pen_data.lc = fgcolor;
  157.             C_CANVAS->grx_pen_style = GRX_pen_solid;
  158.             return;
  159.           case BITMAP_PATTERN_OPAQUE:
  160.             usedbgc = realbgc;
  161.           case BITMAP_PATTERN_TRANSPARENT:
  162.             C_CANVAS->grx_penpatt.gp_bmp_data =
  163.                 srgp__bitmapPatternTable[C_ATTRIB->pen_bitmap_pattern_id];
  164.             C_CANVAS->grx_penpatt.gp_bmp_height  = 8;
  165.             C_CANVAS->grx_penpatt.gp_bmp_fgcolor = fgcolor;
  166.             C_CANVAS->grx_penpatt.gp_bmp_bgcolor = usedbgc;
  167.             C_CANVAS->grx_penpatt.gp_ispixmap    = 0;
  168.             break;
  169.           case PIXMAP_PATTERN:
  170.             C_CANVAS->grx_penpatt =
  171.                 *(srgp__pixmapPatternTable[C_ATTRIB->pen_pixmap_pattern_id]);
  172.             C_CANVAS->grx_penpatt.gp_pxp_oper = wrtmode;
  173.             break;
  174.         }
  175.         C_CANVAS->grx_linepatt.lnp_pattern = &C_CANVAS->grx_penpatt;
  176.         C_CANVAS->grx_linepatt.lnp_option  = &C_CANVAS->grx_lineopt;
  177.         C_CANVAS->grx_pen_data.lp = &C_CANVAS->grx_linepatt;
  178.         C_CANVAS->grx_pen_style = GRX_pen_patterned;
  179. }
  180.  
  181. void srgp__update_grx_fillattributes(void)
  182. {
  183.         int wrtmode = grx_mode_table[C_ATTRIB->write_mode];
  184.         int fgcolor = COLORINDEX(C_ATTRIB->color) | wrtmode;
  185.         int realbgc = COLORINDEX(C_ATTRIB->background_color) | wrtmode;
  186.         int usedbgc = GrNOCOLOR;
  187.  
  188.         switch(C_ATTRIB->fill_style) {
  189.           case SOLID:
  190.             C_CANVAS->grx_fill_data.fc = fgcolor;
  191.             C_CANVAS->grx_fill_style = GRX_fill_solid;
  192.             return;
  193.           case BITMAP_PATTERN_OPAQUE:
  194.             usedbgc = realbgc;
  195.           case BITMAP_PATTERN_TRANSPARENT:
  196.             C_CANVAS->grx_fillpatt.gp_bmp_data =
  197.                 srgp__bitmapPatternTable[C_ATTRIB->fill_bitmap_pattern_id];
  198.             C_CANVAS->grx_fillpatt.gp_bmp_height  = 8;
  199.             C_CANVAS->grx_fillpatt.gp_bmp_fgcolor = fgcolor;
  200.             C_CANVAS->grx_fillpatt.gp_bmp_bgcolor = usedbgc;
  201.             C_CANVAS->grx_fillpatt.gp_ispixmap    = 0;
  202.             break;
  203.           case PIXMAP_PATTERN:
  204.             C_CANVAS->grx_fillpatt =
  205.                 *(srgp__pixmapPatternTable[C_ATTRIB->fill_pixmap_pattern_id]);
  206.             C_CANVAS->grx_fillpatt.gp_pxp_oper = wrtmode;
  207.             break;
  208.         }
  209.         C_CANVAS->grx_fill_data.fp = &C_CANVAS->grx_fillpatt;
  210.         C_CANVAS->grx_fill_style = GRX_fill_patterned;
  211. }
  212.  
  213. static void update_grx_colors(void)
  214. {
  215.         int wrtmode = grx_mode_table[C_ATTRIB->write_mode];
  216.         int fgcolor = COLORINDEX(C_ATTRIB->color) | wrtmode;
  217.         int realbgc = COLORINDEX(C_ATTRIB->background_color) | wrtmode;
  218.         int usedbgc = GrNOCOLOR;
  219.  
  220.         C_CANVAS->grx_textopt.txo_fgcolor.v = fgcolor;
  221.         C_CANVAS->grx_textopt.txo_bgcolor.v = GrNOCOLOR;
  222.         switch(C_ATTRIB->pen_style) {
  223.           case SOLID:
  224.             if(C_CANVAS->grx_pen_style == GRX_pen_solid) {
  225.                 C_CANVAS->grx_pen_data.lc = fgcolor;
  226.                 break;
  227.             }
  228.             C_CANVAS->grx_lineopt.lno_color = fgcolor;
  229.             break;
  230.           case BITMAP_PATTERN_OPAQUE:
  231.             usedbgc = realbgc;
  232.           case BITMAP_PATTERN_TRANSPARENT:
  233.             C_CANVAS->grx_penpatt.gp_bmp_fgcolor = fgcolor;
  234.             C_CANVAS->grx_penpatt.gp_bmp_bgcolor = usedbgc;
  235.             break;
  236.           case PIXMAP_PATTERN:
  237.             C_CANVAS->grx_penpatt.gp_pxp_oper = wrtmode;
  238.             break;
  239.         }
  240.         usedbgc = GrNOCOLOR;
  241.         switch(C_ATTRIB->fill_style) {
  242.           case SOLID:
  243.             C_CANVAS->grx_fill_data.fc = fgcolor;
  244.             break;
  245.           case BITMAP_PATTERN_OPAQUE:
  246.             usedbgc = realbgc;
  247.           case BITMAP_PATTERN_TRANSPARENT:
  248.             C_CANVAS->grx_fillpatt.gp_bmp_fgcolor = fgcolor;
  249.             C_CANVAS->grx_fillpatt.gp_bmp_bgcolor = usedbgc;
  250.             break;
  251.           case PIXMAP_PATTERN:
  252.             C_CANVAS->grx_fillpatt.gp_pxp_oper = wrtmode;
  253.             break;
  254.         }
  255. }
  256.  
  257. #endif
  258.  
  259.  
  260. /** WRITE_MODE
  261. X11 implementation:
  262.    Both GC's must be modified.
  263. **/
  264.  
  265. void
  266. SRGP_setWriteMode (writeMode value)
  267. {
  268.    if (value == __CURATT(write_mode)) return;
  269.  
  270.    DEBUG_AIDS{
  271.       SRGP_trace (SRGP_logStream, "SRGP_setWriteMode  %d\n", value);
  272.       srgp_check_system_state();
  273.       srgp_check_write_mode(value);
  274.       LeaveIfNonFatalErr();
  275.    }
  276.  
  277.    srgp__curActiveCanvasSpec.attributes.write_mode = value;
  278.  
  279. #ifdef X11
  280.    if (XWHITE == 0)
  281.        value = writemode_table[value];
  282.    else
  283.        value = inv_writemode_table[value];
  284.    XSetFunction
  285.       (srgpx__display,
  286.        srgp__curActiveCanvasSpec.gc_frame,
  287.        value);
  288.    XSetFunction
  289.       (srgpx__display,
  290.        srgp__curActiveCanvasSpec.gc_fill,
  291.        value);
  292. #endif
  293. #ifdef THINK_C
  294.    ComputeFrameTransfermode();
  295.    ComputeFillTransfermode();
  296.    SetTextTransfermode();
  297. #endif
  298. #ifdef GRX
  299.    update_grx_colors();
  300. #endif
  301. }
  302.  
  303.  
  304.  
  305. /** CLIP_RECTANGLE
  306. Both GC's must be modified.
  307. **/
  308. void
  309. SRGP_setClipRectangle (rectangle rect)
  310. {
  311. #ifdef X11
  312.    XRectangle xrect;
  313. #endif
  314. #ifdef THINK_C
  315.    Rect r;
  316. #endif
  317.  
  318.    DEBUG_AIDS{
  319.       SRGP_trace (SRGP_logStream, "SRGP_setClipRect  (%d,%d)->(%d,%d)\n", ExplodeRect(rect));
  320.       srgp_check_system_state();
  321.       srgp_check_rectangle
  322.          (rect.bottom_left.x, rect.bottom_left.y,
  323.           rect.top_right.x, rect.top_right.y);
  324.       LeaveIfNonFatalErr();
  325.    }
  326.  
  327.    srgp__curActiveCanvasSpec.attributes.clip_rectangle = rect;
  328.  
  329. #ifdef X11
  330.    xrect.x = rect.bottom_left.x;
  331.    xrect.y = FIXED(rect.top_right.y);
  332.    xrect.width = (rect.top_right.x - rect.bottom_left.x + 1);
  333.    xrect.height = (rect.top_right.y - rect.bottom_left.y + 1);
  334.    XSetClipRectangles
  335.       (srgpx__display,
  336.        srgp__curActiveCanvasSpec.gc_frame,
  337.        0, 0,
  338.        &xrect, 1, YXSorted);
  339.    XSetClipRectangles
  340.       (srgpx__display,
  341.        srgp__curActiveCanvasSpec.gc_fill,
  342.        0, 0,
  343.        &xrect, 1, YXSorted);
  344. #endif
  345.  
  346. #ifdef THINK_C
  347.    r = FIXED_RECT(ExplodeRect(rect));
  348.    ClipRect(&r);
  349. #endif
  350. #ifdef GRX
  351.         GrSetClipBox(rect.bottom_left.x,
  352.             FIXED(rect.top_right.y),
  353.             rect.top_right.x,
  354.             FIXED(rect.bottom_left.y)
  355.         );
  356. #endif
  357. }
  358.  
  359.  
  360.  
  361.  
  362. /** FILL STYLE
  363. Only the fill GC is to be modified.
  364. The SRGP fill-style maps directly to X's fill-style.
  365. **/
  366. void
  367. SRGP_setFillStyle (drawStyle value)
  368. {
  369.    if (value == __CURATT(fill_style)) return;
  370.  
  371.    DEBUG_AIDS{
  372.       SRGP_trace (SRGP_logStream, "SRGP_setFillStyle  %d\n", value);
  373.       srgp_check_system_state();
  374.       srgp_check_fill_style(value);
  375.       LeaveIfNonFatalErr();
  376.    }
  377.  
  378.    srgp__curActiveCanvasSpec.attributes.fill_style = value;
  379.  
  380. #ifdef X11
  381.    XSetFillStyle (srgpx__display, srgp__curActiveCanvasSpec.gc_fill, value);
  382. #endif
  383.  
  384. #ifdef THINK_C
  385.    ComputeFillTransfermode();
  386.    srgp__curActiveCanvasSpec.pat_fill = (Pattern*)
  387.       ((value == SOLID) ?
  388.           black :  /*Mac's "solid" pattern*/
  389.           srgp__bitmapPatternTable
  390.              [srgp__curActiveCanvasSpec.attributes.fill_bitmap_pattern_id]);
  391. #endif
  392. #ifdef GRX
  393.    srgp__update_grx_fillattributes();
  394. #endif
  395. }
  396.  
  397. /*!*/
  398. void
  399. SRGP_setFillBitmapPattern (int value)
  400. {
  401.    if (value == __CURATT(fill_bitmap_pattern_id)) return;
  402.  
  403.    DEBUG_AIDS{
  404.       SRGP_trace (SRGP_logStream, "SRGP_setFillBitmapPattern  %d\n", value);
  405.       srgp_check_system_state();
  406.       srgp_check_pattern_index(value);
  407.       srgp_check_pattern_table_entry(srgp__bitmapPatternTable[value]);
  408.       LeaveIfNonFatalErr();
  409.    }
  410.  
  411.    srgp__curActiveCanvasSpec.attributes.fill_bitmap_pattern_id = value;
  412.  
  413. #ifdef X11
  414.    XSetStipple
  415.       (srgpx__display,
  416.        srgp__curActiveCanvasSpec.gc_fill,
  417.        srgp__bitmapPatternTable[value]);
  418. #endif
  419.  
  420. #ifdef THINK_C
  421.    if (srgp__curActiveCanvasSpec.attributes.fill_style != SOLID)
  422.       srgp__curActiveCanvasSpec.pat_fill = (Pattern*)srgp__bitmapPatternTable[value];
  423. #endif
  424. #ifdef GRX
  425.    srgp__update_grx_fillattributes();
  426. #endif
  427. }
  428.  
  429. /*!*/
  430. void
  431. SRGP_setFillPixmapPattern (int value)
  432. {
  433.    if (value == __CURATT(fill_pixmap_pattern_id)) return;
  434.  
  435.    DEBUG_AIDS{
  436.       SRGP_trace (SRGP_logStream, "SRGP_setFillPixmapPattern  %d\n", value);
  437.       srgp_check_system_state();
  438.       srgp_check_pattern_index(value);
  439.       srgp_check_pattern_table_entry(srgp__pixmapPatternTable[value]);
  440.       LeaveIfNonFatalErr();
  441.    }
  442.  
  443.    srgp__curActiveCanvasSpec.attributes.fill_pixmap_pattern_id = value;
  444.  
  445. #ifdef X11
  446.    gcvals.tile = srgp__pixmapPatternTable[value];
  447.    XChangeGC (srgpx__display, srgp__curActiveCanvasSpec.gc_fill,
  448.               GCTile, &gcvals);
  449. #endif
  450. #ifdef GRX
  451.    srgp__update_grx_fillattributes();
  452. #endif
  453. }
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462. /** PEN STYLE
  463. X11 implementation:
  464.    Only the frame GC is to be modified.
  465.    The SRGP pen-style maps directly to X's fill-style.
  466. **/
  467.  
  468. void
  469. SRGP_setPenStyle (drawStyle value)
  470. {
  471.    if (value == __CURATT(pen_style)) return;
  472.  
  473.    DEBUG_AIDS{
  474.       SRGP_trace (SRGP_logStream, "SRGP_setPenStyle  %d\n", value);
  475.       srgp_check_system_state();
  476.       srgp_check_fill_style(value);
  477.       LeaveIfNonFatalErr();
  478.    }
  479.  
  480.    srgp__curActiveCanvasSpec.attributes.pen_style = value;
  481.  
  482. #ifdef X11
  483.    XSetFillStyle (srgpx__display, srgp__curActiveCanvasSpec.gc_frame, value);
  484. #endif
  485. #ifdef THINK_C
  486.    ComputeFrameTransfermode();
  487.    srgp__curActiveCanvasSpec.pat_frame = (Pattern*)
  488.       ((value == SOLID) ?
  489.          black :  /*Mac's "solid" pattern*/
  490.          srgp__bitmapPatternTable
  491.             [srgp__curActiveCanvasSpec.attributes.pen_bitmap_pattern_id]);
  492. #endif
  493. #ifdef GRX
  494.    srgp__update_grx_penattributes();
  495. #endif
  496. }
  497.  
  498. /*!*/
  499. void
  500. SRGP_setPenBitmapPattern (int value)
  501. {
  502.    if (value == __CURATT(pen_bitmap_pattern_id)) return;
  503.  
  504.    DEBUG_AIDS{
  505.       SRGP_trace (SRGP_logStream, "SRGP_setPenBitmapPattern  %d\n", value);
  506.       srgp_check_system_state();
  507.       srgp_check_pattern_index(value);
  508.       srgp_check_pattern_table_entry(srgp__bitmapPatternTable[value]);
  509.       LeaveIfNonFatalErr();
  510.    }
  511.  
  512.    srgp__curActiveCanvasSpec.attributes.pen_bitmap_pattern_id = value;
  513.  
  514. #ifdef X11
  515.    XSetStipple
  516.       (srgpx__display,
  517.        srgp__curActiveCanvasSpec.gc_frame,
  518.        srgp__bitmapPatternTable[value]);
  519. #endif
  520.  
  521. #ifdef THINK_C
  522.    if (srgp__curActiveCanvasSpec.attributes.pen_style != SOLID)
  523.       srgp__curActiveCanvasSpec.pat_frame =
  524.          (Pattern*) srgp__bitmapPatternTable[value];
  525. #endif
  526. #ifdef GRX
  527.    srgp__update_grx_penattributes();
  528. #endif
  529. }
  530.  
  531.  
  532.  
  533. /*!*/
  534. void
  535. SRGP_setPenPixmapPattern (int value)
  536. {
  537.    if (value == __CURATT(pen_pixmap_pattern_id)) return;
  538.  
  539.    DEBUG_AIDS{
  540.       SRGP_trace (SRGP_logStream, "SRGP_setPenPixmapPattern  %d\n", value);
  541.       srgp_check_system_state();
  542.       srgp_check_pattern_index(value);
  543.       srgp_check_pattern_table_entry(srgp__pixmapPatternTable[value]);
  544.       LeaveIfNonFatalErr();
  545.    }
  546.  
  547.    srgp__curActiveCanvasSpec.attributes.pen_pixmap_pattern_id = value;
  548.  
  549. #ifdef X11
  550.    gcvals.tile = srgp__pixmapPatternTable[value];
  551.    XChangeGC (srgpx__display, srgp__curActiveCanvasSpec.gc_frame,
  552.               GCTile, &gcvals);
  553. #endif
  554. #ifdef GRX
  555.    srgp__update_grx_penattributes();
  556. #endif
  557. }
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564. /** MARKER ATTRIBUTES
  565. **/
  566.  
  567. void
  568. SRGP_setMarkerSize (int value)
  569. {
  570.    if (value == __CURATT(marker_size)) return;
  571.  
  572.    DEBUG_AIDS{
  573.       SRGP_trace (SRGP_logStream, "SRGP_setMarkerSize  %d\n", value);
  574.       srgp_check_system_state();
  575.       srgp_check_marker_size(value);
  576.       LeaveIfNonFatalErr();
  577.    }
  578.  
  579.    srgp__curActiveCanvasSpec.attributes.marker_size = value;
  580. }
  581.  
  582.  
  583. void
  584. SRGP_setMarkerStyle (markerStyle value)
  585. {
  586.    if (value == __CURATT(marker_style)) return;
  587.  
  588.    DEBUG_AIDS{
  589.       SRGP_trace (SRGP_logStream, "SRGP_setMarkerStyle  %d\n", value);
  590.       srgp_check_system_state();
  591.       srgp_check_marker_style(value);
  592.       LeaveIfNonFatalErr();
  593.    }
  594.  
  595.    srgp__curActiveCanvasSpec.attributes.marker_style = value;
  596. }
  597.  
  598.  
  599.  
  600. #ifdef X11
  601. /** TRANSLATING SRGP DASHES TO X
  602. **/
  603. #define LENGTH_OF_DASH_LIST   4
  604. static char dot[] = {4,4,4,4};
  605. static char dash[] = {10,5,10,5};
  606. static char dotdash[] = {12,4,4,4};
  607. static char *(dashmap[NUMBER_OF_LINE_STYLES]) =
  608.    { /*CONTINUOUS: unimportant*/ 0,
  609.      /*DASHED*/ dash,
  610.      /*DOTTED*/ dot,
  611.      /*DOT_DASHED*/ dotdash };
  612.  
  613.  
  614. /** STATIC INTERNAL: SetXLineAttributes()
  615. Notice that when the user desires a line-width of 1, we use 0.
  616. This uses the hardware's fastest line-drawer, according to X.
  617. **/
  618.  
  619. static void SetXLineAttributes()
  620. {
  621.    XSetLineAttributes
  622.       (
  623.        srgpx__display,
  624.        srgp__curActiveCanvasSpec.gc_frame,
  625.        ((srgp__curActiveCanvasSpec.attributes.line_width == 1) ?
  626.         0 : srgp__curActiveCanvasSpec.attributes.line_width),
  627.        ((srgp__curActiveCanvasSpec.attributes.line_style==CONTINUOUS) ?
  628.         LineSolid : LineOnOffDash),
  629.        CapButt,         /* CAPS and JOINS are no-ops when line width = 0 */
  630.        JoinBevel);
  631. }
  632. #endif
  633.  
  634.  
  635.  
  636. /*!*/
  637. void
  638. SRGP_setLineStyle (lineStyle value)
  639. {
  640.    if (value == __CURATT(line_style)) return;
  641.  
  642.    DEBUG_AIDS{
  643.       SRGP_trace (SRGP_logStream, "SRGP_setLineStyle  %d\n", value);
  644.       srgp_check_system_state();
  645.       srgp_check_line_style(value);
  646.       LeaveIfNonFatalErr();
  647.    }
  648.  
  649.    srgp__curActiveCanvasSpec.attributes.line_style = value;
  650.  
  651. #ifdef X11
  652.    if (value != CONTINUOUS)
  653.       XSetDashes (srgpx__display, srgp__curActiveCanvasSpec.gc_frame,
  654.                   0, dashmap[value], LENGTH_OF_DASH_LIST);
  655.    SetXLineAttributes();
  656. #endif
  657. #ifdef GRX
  658.    srgp__update_grx_penattributes();
  659. #endif
  660. }
  661.  
  662.  
  663.  
  664. /*!*/
  665. void
  666. SRGP_setLineWidth (int value)
  667. {
  668.    if (value == __CURATT(line_width)) return;
  669.  
  670.    DEBUG_AIDS{
  671.       SRGP_trace (SRGP_logStream, "SRGP_setLineWidth  %d\n", value);
  672.       srgp_check_system_state();
  673.       srgp_check_line_width(value);
  674.       LeaveIfNonFatalErr();
  675.    }
  676.  
  677.    srgp__curActiveCanvasSpec.attributes.line_width = value;
  678.  
  679. #ifdef X11
  680.    SetXLineAttributes ();
  681. #endif
  682. #ifdef THINK_C
  683.    PenSize (value,value);
  684. #endif
  685. #ifdef GRX
  686.    srgp__update_grx_penattributes();
  687. #endif
  688. }
  689.  
  690.  
  691.  
  692.  
  693.  
  694. /** ATTRIBUTES RELATED TO COLOR
  695. **/
  696.  
  697. void
  698. SRGP_setPlaneMask (int value)
  699. {
  700.    if (value == __CURATT(plane_mask)) return;
  701.  
  702.    DEBUG_AIDS{
  703.       SRGP_trace (SRGP_logStream, "SRGP_setPlaneMask  %x\n", value);
  704.       srgp_check_system_state();
  705.       LeaveIfNonFatalErr();
  706.    }
  707.  
  708.    srgp__curActiveCanvasSpec.attributes.plane_mask = value;
  709.  
  710. #ifdef X11
  711.    XSetPlaneMask
  712.       (srgpx__display,
  713.        srgp__curActiveCanvasSpec.gc_fill, (unsigned long) value);
  714.    XSetPlaneMask
  715.       (srgpx__display,
  716.        srgp__curActiveCanvasSpec.gc_frame, (unsigned long) value);
  717. #endif
  718. }
  719.  
  720.  
  721. void
  722. SRGP_setColor (int value)
  723. {
  724.    if (value == __CURATT(color)) return;
  725.  
  726.    DEBUG_AIDS{
  727.       SRGP_trace (SRGP_logStream, "SRGP_setColor  %x\n", value);
  728.       srgp_check_system_state();
  729.       SRGP_correct_color(value);
  730.       LeaveIfNonFatalErr();
  731.    }
  732.  
  733.    if (value > srgp__max_pixel_value)
  734.       value = srgp__max_pixel_value;
  735.    srgp__curActiveCanvasSpec.attributes.color = value;
  736.  
  737. #ifdef X11
  738.    XSetForeground(srgpx__display, srgp__curActiveCanvasSpec.gc_fill,
  739.                   XCOLOR(COLORINDEX(value)));
  740.    XSetForeground(srgpx__display, srgp__curActiveCanvasSpec.gc_frame,
  741.                   XCOLOR(COLORINDEX(value)));
  742. #endif
  743.  
  744. #ifdef THINK_C
  745. #ifdef COLOR_QUICKDRAW
  746.    srgp__curActiveCanvasSpec.drawable.win->fgColor = (COLORINDEX(value));
  747. #else
  748.    ComputeFrameTransfermode();
  749.    ComputeFillTransfermode();
  750.    SetTextTransfermode();
  751. #endif
  752. #endif
  753. #ifdef GRX
  754.    update_grx_colors();
  755. #endif
  756. }
  757.  
  758.  
  759.  
  760. void
  761. SRGP_setBackgroundColor (int value)
  762. {
  763.    if (value == __CURATT(background_color)) return;
  764.  
  765.    DEBUG_AIDS{
  766.       SRGP_trace (SRGP_logStream, "SRGP_setBackgroundColor  %x\n", value);
  767.       srgp_check_system_state();
  768.       SRGP_correct_color(value);
  769.       LeaveIfNonFatalErr();
  770.    }
  771.  
  772.    if (value > srgp__max_pixel_value)
  773.       value = srgp__max_pixel_value;
  774.    srgp__curActiveCanvasSpec.attributes.background_color = value;
  775.  
  776. #ifdef X11
  777.    XSetBackground(srgpx__display, srgp__curActiveCanvasSpec.gc_fill,
  778.                   XCOLOR(COLORINDEX(value)));
  779.    XSetBackground(srgpx__display, srgp__curActiveCanvasSpec.gc_frame,
  780.                   XCOLOR(COLORINDEX(value)));
  781. #endif
  782.  
  783. #ifdef THINK_C
  784. #ifdef COLOR_QUICKDRAW
  785.    srgp__curActiveCanvasSpec.drawable.win->bkColor = (COLORINDEX(value));
  786. #endif
  787. #endif
  788. #ifdef GRX
  789.    update_grx_colors();
  790. #endif
  791. }
  792.  
  793.  
  794.  
  795. /** Load Single Color
  796. A convenience subroutine for setting a single color table entry
  797. **/
  798. void SRGP_loadSingleColor
  799.    (int startentry,
  800.     unsigned short redi,
  801.     unsigned short greeni,
  802.     unsigned short bluei)
  803. {
  804.    PUSH_TRACE;
  805.    SRGP_loadColorTable (startentry, 1, &redi, &greeni, &bluei);
  806.    POP_TRACE;
  807. }
  808.  
  809.  
  810.  
  811.  
  812. /** FONT
  813. The frame gc is used to draw text.  This is a cheat, and violates SRGP's
  814. spec.  This will be fixed someday.
  815. **/
  816. void
  817. SRGP_setFont (int value)
  818. {
  819.    if (value == __CURATT(font)) return;
  820.  
  821.    DEBUG_AIDS{
  822.       SRGP_trace (SRGP_logStream, "SRGP_setFont  %d\n", value);
  823.       srgp_check_system_state();
  824.       srgp_check_extant_font(value);
  825.       LeaveIfNonFatalErr();
  826.    }
  827.  
  828.    srgp__curActiveCanvasSpec.attributes.font = value;
  829.  
  830. #ifdef X11
  831.    XSetFont
  832.       (srgpx__display,
  833.        srgp__curActiveCanvasSpec.gc_frame,
  834.        srgp__fontTable[value]->fid);
  835. #endif
  836. #ifdef THINK_C
  837.       TextFont(srgp__fontTable[value].txFont);
  838.       TextSize(srgp__fontTable[value].txSize);
  839.       TextFace(srgp__fontTable[value].txFace);
  840. #endif
  841. #ifdef GRX
  842.     C_CANVAS->grx_textopt.txo_font = srgp__fontTable[value];
  843.     C_CANVAS->grx_textopt.txo_xmag = 1;
  844.     C_CANVAS->grx_textopt.txo_ymag = 1;
  845.     C_CANVAS->grx_textopt.txo_fgcolor.v =
  846.         COLORINDEX(C_ATTRIB->color) | grx_mode_table[C_ATTRIB->write_mode];
  847.     C_CANVAS->grx_textopt.txo_bgcolor.v = GrNOCOLOR;
  848.     C_CANVAS->grx_textopt.txo_direct = GR_TEXT_DEFAULT;
  849.     C_CANVAS->grx_textopt.txo_xalign = GR_ALIGN_DEFAULT;
  850.     C_CANVAS->grx_textopt.txo_yalign = GR_ALIGN_BASELINE;
  851.     C_CANVAS->grx_textopt.txo_chrtype = GR_BYTE_TEXT;
  852. #endif
  853. }
  854.  
  855.  
  856.  
  857. /** BATCH SET ATTRIBUTES
  858. Woefully inefficient, but at least I don't reset attributes whose
  859. value has not changed.
  860. **/
  861.  
  862. void
  863. SRGP_setAttributes (attribute_group *att_group)
  864. {
  865.    SRGP_trace (SRGP_logStream, "SRGP_setAttributes 0x%x\n", att_group);
  866.    PUSH_TRACE;
  867.    SRGP_setWriteMode (att_group->write_mode);
  868.    SRGP_setClipRectangle (att_group->clip_rectangle);
  869.  
  870.    SRGP_setFont (att_group->font);
  871.    SRGP_setLineStyle (att_group->line_style);
  872.    SRGP_setLineWidth (att_group->line_width);
  873.    SRGP_setColor (att_group->color);
  874.    SRGP_setPlaneMask (att_group->plane_mask);
  875.    SRGP_setBackgroundColor (att_group->background_color);
  876.    SRGP_setFillStyle (att_group->fill_style);
  877.    SRGP_setFillPixmapPattern (att_group->fill_pixmap_pattern_id);
  878.    SRGP_setFillBitmapPattern (att_group->fill_bitmap_pattern_id);
  879.    SRGP_setPenStyle (att_group->pen_style);
  880.    SRGP_setPenPixmapPattern (att_group->pen_pixmap_pattern_id);
  881.    SRGP_setPenBitmapPattern (att_group->pen_bitmap_pattern_id);
  882.    SRGP_setMarkerSize (att_group->marker_size);
  883.    SRGP_setMarkerStyle (att_group->marker_style);
  884.    POP_TRACE;
  885. }
  886.